<?php

class LoginAction extends Action  {

	public function _initialize(){
		
	}

    public function index(){
    	
        D('Admin')->loginout();
    	$this->display();
    }

    public function dologin(){
        $map['username'] = I('post.username');
        $map['password'] = md5(I('post.password'));
        $login = D('Admin')->login($map);
        if($login){
            $this->success('登陆成功！',U('Index/index'));
        }else{
            $this->error('登陆失败！',U('Login/index'));
        }
    }

    public function loginout(){
       D('Admin')->loginout();
       $this->success('退出成功！',U('Login/index'));
    }

    public function password(){
        $this->display();
    }

    public function dopassword(){

        $info = I('post.');
        if($info['newpassword'] != $info['repassword']){
             $this->error('新密码不一致，请从新填写！',U('Login/password'));
        }
        $map['admin'] = 'admin';
        $map['password'] = md5($info['password']);
        $user = D('Admin')->where($map)->find();
        if($user['uid']){
            $data['password'] = md5($info['newpassword']);
            $save = D('Admin')->where($map)->save($data);
            if($save){
                $this->success('修改成功！',U('Login/index'));
            }else{
                $this->error('修改失败！',U('Login/password'));
            }
        }else{
            $this->error('修改失败,原密码不正确！',U('Login/password'));
        }


       
    }
}